package com.shixj.easy.spider.factory;

import com.shixj.easy.spider.model.Catalog;
import com.shixj.easy.spider.model.Novel;
import com.shixj.easy.spider.model.RegexConfig;
import com.shixj.ef.vo.FetchResult;
import org.jsoup.nodes.Document;


/**
 * Created by shixj on 2018/1/15.
 */
public class DefaultCatalogFactory implements EntityFactory {

    /**
     * 转换novel封面信息
     *
     * @param result
     * @return
     */
    @Override
    public Catalog build(FetchResult result, RegexConfig regexConfig) {
        EntityFactory factory = new DefaultNovelFactory();
        Novel novel = (Novel) factory.build(result, regexConfig);
        Catalog catalog = new Catalog();
        catalog.setNovel(novel);
        /**
         * 解析章节列表
         */
        Document document = result.getDocument();
        catalog.setChapterList(getCatalog(document, regexConfig));
        return catalog;
    }
}
